<template>
  <div class="message-page">
    <div class="message-list">
      <div v-if="messages.length === 0" class="no-message">
        <NoData text="Tidak Ada Pesan" />
      </div>
      
      <div v-else class="message-items">
        <div v-for="(message, index) in messages" :key="index" 
             class="message-item"
             :class="message.status"
             @click="viewMessageDetail(message.id)">
          <div class="message-left">
            <div class="notification-icon">
              <img src="@/assets/images/user/iconInfo.png" alt="notification" />
            </div>
          </div>
          <div class="message-right">
            <div class="message-content">{{ message.content }}</div>
            <div class="message-time">{{ message.time }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
  
<script setup>
// 导入所需的依赖
import NoData from '@/components/NoData.vue'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'

// 初始化数据
const router = useRouter()
const messages = ref([])

// 生命周期钩子
onMounted(() => {
  // 获取消息列表
  getMessageList()
})

// 方法定义
function getMessageList() {
  // 模拟获取消息列表
  setTimeout(() => {
    messages.value = [
      {
        id: '2667909174546495',
        content: 'Penarikan Anda [2667909174546495] telah berhasil diproses. Dana telah tiba pada 12:53 24/04/2025',
        time: '12:53 24/04/2025',
        status: 'success'
      },
      {
        id: '2667909174546769',
        content: 'Maaf, penarikan Anda [2667909174546769] gagal. Alasannya: informasi akun mungkin salah. S...',
        time: '11:19 24/04/2025',
        status: 'error'
      },
      {
        id: 'T1431',
        content: 'Anda telah berhasil berlangganan produk investasi[T1431]. Terima kasih atas kepercayaan da...',
        time: '14:19 19/04/2025',
        status: 'success'
      }
    ]
  }, 300)
}

function viewMessageDetail(id) {
  router.push({
    path: '/user/messagedetail',
    query: { id }
  })
}
</script>
  
<style lang="less" scoped>
.message-page {
  min-height: 100vh;
  background-color: #1c1815;
  padding-bottom: 30px;
}

.page-header {
  display: flex;
  align-items: center;
  padding: 15px;
  position: relative;
  background-image: url('@/assets/images/user/Topbg.png');
  background-size: cover;
  background-position: top center;
  
  .back-button {
    position: absolute;
    left: 15px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    
    img {
      width: 100%;
      height: 100%;
    }
  }
  
  .page-title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: #f6e0ca;
  }
}

.message-list {
  padding: 10px;
}

.no-message {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
}

.message-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-item {
  background-color: #2a2421;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: background-color 0.2s;
  
  &:active {
    background-color: #322e2b;
  }
  
  .message-left {
    margin-right: 15px;
    flex-shrink: 0;
    padding-top: 2px;
    
    .notification-icon {
      width: 24px;
      height: 24px;
      border-radius: 50%;
      background-color: #443f3c;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      
      img {
        width: 16px;
        height: 16px;
        opacity: 0.8;
      }
    }
  }
  
  .message-right {
    flex: 1;
    
    .message-content {
      font-size: 14px;
      color: #ccc;
      line-height: 1.5;
      margin-bottom: 12px;
      word-break: break-word;
      font-weight: 300;
    }
    
    .message-time {
      font-size: 12px;
      color: #777;
      text-align: right;
      font-weight: 300;
      border-top: 1px dashed #333;
      padding-top: 10px;
    }
  }
}

// 针对不同类型消息的样式
// .message-item.success .notification-icon {
//   background-color: rgba(35, 155, 86, 0.2);
//   img {
//     filter: hue-rotate(120deg);
//   }
// }

// .message-item.error .notification-icon {
//   background-color: rgba(236, 61, 61, 0.2);
//   img {
//     filter: hue-rotate(0deg) saturate(2);
//   }
// }
</style>
  